package com.easylinkin.linkappapi.quality.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easylinkin.linkappapi.common.model.RequestModel;
import com.easylinkin.linkappapi.quality.dto.QualityInspectionDTO;
import com.easylinkin.linkappapi.quality.entity.QualityInspection;
import com.easylinkin.linkappapi.quality.service.QualityInspectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

/**
 * @author: kan yuanfeng
 * @Date: 2020/11/04 11:42
 * @Description: 巡检记录管理
 */
@RestController
@RequestMapping("qualityInspection")
@Api(tags = "巡检记录管理")
public class QualityInspectionController {
  
  @Autowired
  private QualityInspectionService qualityInspectionService;

  /**
   * @Description: 增加巡检记录
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @PostMapping
  @ApiOperation("增加巡检记录")
  public RestMessage insert(@RequestBody QualityInspection qualityInspection){
    qualityInspectionService.insert(qualityInspection);
    return RestBuilders.successBuilder().build();
  }

  /**
   * @Description: 删除巡检记录（包含批量删除）
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @DeleteMapping
  @ApiOperation("删除巡检记录（包含批量删除）")
  public RestMessage delBatch(@RequestBody QualityInspection qualityInspection){
    Assert.notEmpty(qualityInspection.getIds(),"id不能为空");
    qualityInspectionService.removeByIds(qualityInspection.getIds());
    return RestBuilders.successBuilder().build();
  }

  /**
   * @Description: 编辑巡检记录
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @PutMapping
  @ApiOperation("编辑巡检记录")
  public RestMessage updateById(@RequestBody QualityInspection qualityInspection){
    Assert.notNull(qualityInspection.getId(),"id不能为空");
    qualityInspectionService.updateOne(qualityInspection);
    return RestBuilders.successBuilder().build();
  }

  /**
   * @Description: 根据id查询巡检记录详情
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @GetMapping("{id}")
  @ApiOperation("根据id查询巡检记录详情")
  public RestMessage findById(@PathVariable("id")Long id) {
    Assert.notNull(id,"id不能为空");
    QualityInspection qualityInspection = qualityInspectionService.getById(id);
    return RestBuilders.successBuilder().data(qualityInspection).build();
  }

  /**
   * @Description: 根据条件，分页(不分页)查询
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @PostMapping("list")
  @ApiOperation("根据条件，分页(不分页)查询")
  public RestMessage queryListByPage(@RequestBody RequestModel<QualityInspectionDTO> requestModel){
    Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
    Assert.notNull(requestModel.getPage(), "page 不能为空");
    IPage<QualityInspectionDTO> record =  qualityInspectionService.queryListByPage(requestModel);
    return RestBuilders.successBuilder().data(record).build();
  }

  /**
   * @Description: 根据条件，分页(不分页)查询
   * @author tong jie
   * @date 2020/11/04 11:42
   */
  @PostMapping("openapi/list")
  @ApiOperation("根据条件，分页(不分页)查询")
  public RestMessage queryListByPageFromEnterprise(@RequestBody RequestModel<QualityInspectionDTO> requestModel){
    Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
    Assert.notNull(requestModel.getPage(), "page 不能为空");
    IPage<QualityInspectionDTO> record =  qualityInspectionService.queryListByPageFromEnterprise(requestModel);
    return RestBuilders.successBuilder().data(record).build();
  }
}

